<template>
  <el-dialog
    title="选择城市"
    :visible.sync="dialogVisible"
    width="350px"
    top="40%">
    <div id="change-city-dialog-content">
<!--      <div align="right">-->
<!--        定位开关:-->
<!--        <el-switch-->
<!--          v-model="isAllowLocation"-->
<!--          active-color="#199b19"-->
<!--          inactive-color="#CCCCCC">-->
<!--        </el-switch>-->
<!--      </div>-->
      <div class="item" v-for="(provinceItem,index) in dict.CoverCity" :key="index">
        <div class="title">
          <span v-text="provinceItem.name"></span>
        </div>
        <div class="list-item">
          <div class="item" v-for="(cityItem,_index) in provinceItem.list" :key="_index" v-text="cityItem.name" :class="{curr:cityItem.name===CurrUser.City}" @click="choose(cityItem)"></div>
          <div class="c"></div>
        </div>
        <div class="c"></div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ChangeCityDialog',
  data: function () {
    return {
      dialogVisible: false,
      isBinding: false,
      // isAllowLocation:false
    }
  },
  // watch: {
  //   isAllowLocation:function (){
  //     if (this.isAllowLocation && localStorage.getItem("allowLocation")==='0'){
  //       localStorage.setItem("allowLocation","1")
  //       setTimeout(function () {
  //         location.reload()
  //       },500)
  //     }
  //     if (!this.isAllowLocation && localStorage.getItem("allowLocation")==='1'){
  //       localStorage.setItem("allowLocation","0")
  //       setTimeout(function () {
  //         location.reload()
  //       },500)
  //     }
  //     console.log('isAllowLocation:',localStorage.getItem("allowLocation"))
  //   }
  // },
  mounted () {
    let $this = this
    $this.bus.$on('ChangeCityDialogCallBus', function () {
      // $this.isAllowLocation=localStorage.getItem("allowLocation")==='1'
      $this.dialogVisible = true
      $this.$forceUpdate()
    })
  },
  methods: {
    choose: function (city) {
      this.$confirm('您确认要切换至【'+city.name+'】?', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.CurrUser.setCity(city.name)
        this.CurrUser.setLocation(city.location)
        window.location.reload()
      })
    }
  }
}
</script>

<style scoped>

</style>
